package com.nongye.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nongye.common.annotation.Log;
import com.nongye.common.core.controller.BaseController;
import com.nongye.common.core.domain.AjaxResult;
import com.nongye.common.enums.BusinessType;
import com.nongye.system.domain.CropsData;
import com.nongye.system.service.ICropsDataService;
import com.nongye.common.utils.poi.ExcelUtil;
import com.nongye.common.core.page.TableDataInfo;

/**
 * 农作物数据Controller
 * 
 * @author nongye
 * @date 2023-10-10
 */
@Api(value = "农作物数据",tags = "农作物数据")
@RestController
@RequestMapping("/system/cropsdata")
public class CropsDataController extends BaseController
{
    @Autowired
    private ICropsDataService cropsDataService;

    /**
     * 查询农作物数据列表
     */
    @ApiOperation(value = "查询农作物数据列表")
    @GetMapping("/list")
    public TableDataInfo list(CropsData cropsData)
    {
        startPage();
        List<CropsData> list = cropsDataService.selectCropsDataList(cropsData);
        return getDataTable(list);
    }

    /**
     * 导出农作物数据列表
     */
    @ApiOperation(value = "导出农作物数据列表")
    @Log(title = "农作物数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CropsData cropsData)
    {
        List<CropsData> list = cropsDataService.selectCropsDataList(cropsData);
        ExcelUtil<CropsData> util = new ExcelUtil<CropsData>(CropsData.class);
        util.exportExcel(response, list, "农作物数据数据");
    }

    /**
     * 获取农作物数据详细信息
     */
    @ApiOperation(value = "获取农作物数据详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cropsDataService.selectCropsDataById(id));
    }

    /**
     * 新增农作物数据
     */
    @ApiOperation(value = "新增农作物数据")
    @Log(title = "农作物数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CropsData cropsData)
    {
        return toAjax(cropsDataService.insertCropsData(cropsData));
    }

    /**
     * 修改农作物数据
     */
    @ApiOperation(value = "修改农作物数据")
    @Log(title = "农作物数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CropsData cropsData)
    {
        return toAjax(cropsDataService.updateCropsData(cropsData));
    }

    /**
     * 删除农作物数据
     */
    @ApiOperation(value = "删除农作物数据")
    @Log(title = "农作物数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cropsDataService.deleteCropsDataByIds(ids));
    }
}
